package servlet;

import java.io.IOException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.Manager;

import swimv2.session.IAbilityManagerRemote;
import swimv2.session.ILoginRemote;
import swimv2.session.IStatisticModuleRemote;
import utils.SeU;

public class AbilityRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	public AbilityRequest() {
        super();
    }
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.process(request,response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.process(request,response);
	}
	
	private void process(HttpServletRequest request,HttpServletResponse response) {
		String nextPage = "Home";
		
		try {
			Context c = new InitialContext();
			IAbilityManagerRemote a= (IAbilityManagerRemote)c.lookup("IAbilityManagerRemote");
			
			a.createAbility(request.getParameter("nome"));
			
			nextPage= "Home_Admin";
			
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			RequestDispatcher dispatcher = request
					.getRequestDispatcher(nextPage);
			if (dispatcher!=null)
				try {
					dispatcher.forward(request, response);
				} catch (ServletException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
	}
	
}
